﻿using System.Collections.Generic;
using System.Web.Mvc;
using WebSite.ViewModels.Fields;
using WebSite.ViewModels.ViewModelExtensions.DetailsViewModelExtensions;

namespace WebSite.ViewModels.DetailsViewModels
{
    public abstract class DetailsViewModel : CRUDViewModel
    {
        public IDetailsViewModelExtension[] DetailsViewModelExtensions { get; set; }
        public bool CanDelete { get; set; }
        public bool CanEdit { get; set; }

        public virtual IEnumerable<ButtonType> AdditionalButtons
        {
            get { return new ButtonType[0]; }
        }

        protected DetailsViewModel(string title, string message = null)
            : base(title, message)
        {
            DetailsViewModelExtensions = new IDetailsViewModelExtension[0];
            CanDelete = true;
            CanDelete = true;
        }

        public TabsViewModel GetTabsViewModel(HtmlHelper htmlHelper)
        {
            return new TabsViewModel(htmlHelper, ControllerName).AddRange(GetTabs(htmlHelper));
        }

        protected virtual IEnumerable<TabItem> GetTabs(HtmlHelper htmlHelper)
        {
            yield return new TabItem("Geral",
                "~/Content/information.png",
                new FormLayoutViewModel(htmlHelper)
                    .AddFieldRange(GetGeralFields())
                    .Render(2, 10).ToHtmlString());
        }

        protected virtual IEnumerable<IField> GetGeralFields()
        {
            List<IField> result = new List<IField>();
            foreach (IDetailsViewModelExtension editViewModelExtension in DetailsViewModelExtensions)
            {
                result.AddRange(editViewModelExtension.GetGeralAdditionalFields(Model));
            }
            return result;
        }
    }
}